﻿using AutoMapper;
using XfTech.SmartTms.Books.Dtos;
using XfTech.SmartTms.Entities;
using XfTech.SmartTms.Entities.Issues;
using XfTech.SmartTms.Issues.Dtos;
using XfTech.SmartTms.Vehicles.Dtos;

namespace XfTech.SmartTms
{
    public class SmartTmsApplicationAutoMapperProfile : Profile
    {
        public SmartTmsApplicationAutoMapperProfile()
        {
            /* You can configure your AutoMapper mapping configuration here.
             * Alternatively, you can split your mapping configurations
             * into multiple profile classes for a better organization. */

            CreateMap<Book, BookDto>();
            CreateMap<BookDto, Book>();
            CreateMap<CreateUpdateBookDto, Book>();

            CreateMap<Issue, IssueShowDto>();

            //从车辆实体Vehicle，映射到VehicleDto
            CreateMap<Vehicle, VehicleDto>()
                .ForMember(d => d.Length, o => o.MapFrom(v => v.Size.Length)) //当有值对象时需要这样配置
                .ForMember(d => d.Width, o => o.MapFrom(v => v.Size.Width))
                .ForMember(d => d.Height, o => o.MapFrom(v => v.Size.Height));

        }
    }
}
